﻿using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace MeterControl.Services
{
    public class PowerHostedService : BackgroundService
    {
        private readonly ILogger<PowerHostedService> _logger;

        public PowerHostedService( ILogger<PowerHostedService> logger)
        {
            //Constructor’s parameters validations   
            _logger = logger;
        }
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _logger.LogInformation($"TimedExecutService is starting.");
            stoppingToken.Register(() => _logger.LogInformation($"PowerHostedService is stopping 1."));

            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation($"PowerHostedService doing background work.");
                //Doing Somethings
                await Task.Delay(10, stoppingToken);
            }

            _logger.LogInformation($"PowerHostedService is stopping 2.");
        }
    }
}
